-
Notifications
You must be signed in to change notification settings - Fork 109
Add Entity Manifests to Cedar #1102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Entity Manifests to Cedar #1102
Conversation
0920ec4 to
3bc120e
Compare
c081b68 to
266ba3b
Compare
| Ok(RootAccessTrie::new()) | ||
| } | ||
|
|
||
| // TODO is returning the first error correct? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need advice on this TODO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning the first error is fine, but returning all the errors would be more consistent with the rest of the validation APIs.
Re your second question: yes, validation does some additional steps (e.g., handling for templates). If you look at validate and validate_policies here you'll see that there are several pre-processing steps before we get to typecheck_policy (which is what calls typecheck_by_request_env). I think it'd be ideal to add you changes to the main validation path (if possible).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how to add it to the validation path without it getting ugly- it would have to return both the current result and an optional entity manifest.
I'll keep this as-is for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ended up running full validation first before this code path, giving a good error message
cdisselkoen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely a reasonable implementation of the RFC as it currently stands. Some low-level comments, but at a high level this looks great.
bace765 to
a427a9b
Compare
| Ok(RootAccessTrie::new()) | ||
| } | ||
|
|
||
| // TODO is returning the first error correct? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning the first error is fine, but returning all the errors would be more consistent with the rest of the validation APIs.
Re your second question: yes, validation does some additional steps (e.g., handling for templates). If you look at validate and validate_policies here you'll see that there are several pre-processing steps before we get to typecheck_policy (which is what calls typecheck_by_request_env). I think it'd be ideal to add you changes to the main validation path (if possible).
b768da6 to
23caaa0
Compare
469d262 to
f345d3c
Compare
john-h-kastner-aws
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Main point of concern in the assumption that validation errors will be non-empty.
| #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)] | ||
| pub enum EntityRoot { | ||
| /// Literal entity ids | ||
| Literal(EntityUID), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will end up exporting cedar_policy_core::ast::EntityUID from cedar_policy. Not a blocking issue for an experimental feature, but we'll need to introduce some more wrapper type in cedar_policy if we want callers to be able to use this directly as a cedar_policy::EntityUID. Same comment for Var variant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that this should use the existing wrapper EntityUid?
That's a little unfortunate since I can't import it from the validator crate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, Callers should be able to use it as they would the existing EntityUid wrapper. It does get a annoying since you'll end up wanting a wrapper for most of your structs, but we don't want consumers of cedar-policy to ever import cedar-policy-core
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other option would be using the opaque inner struct pattern we use for error messages if users don't need to look inside the Literal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. I think people should be able to get the literal, so for now I'll add a TODO to implement wrappers for everything in api.rs
| } | ||
|
|
||
| PolicyCheck::Fail(errors) => { | ||
| // PANIC SAFETY: policy check fail should be a non-empty vector. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumption might not hold. Check behavior on undefined action and entity types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning the full list of errors would avoid any uncertainty here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea
How should I implement Diagnostic for multiple validation errors? Should it print out the first one? What about when there are no errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can take a look at ParseErrors in Core for precedent. To the first question, at least in that case we chose to just do the first one. To the second question, we used NonEmpty to structurally guarantee we can't have an empty vector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks to the pointer to ParseErrors
I'm still having trouble finding the case where there are no errors reported- could you point me in the right direction? What are undefined action and entity types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One option could be to
- Run full strict mode validation, getting a proper
api::ValidationResult - Run
typecheck_by_request_envto get the type-annotated policies, using panic if we encounter a type error
Another option would be to embed entity manifest computation into the typechecker to make this more efficient. But this seems kind of ugly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still having trouble finding the case where there are no errors reported- could you point me in the right direction? What are undefined action and entity types?
cedar/cedar-policy-validator/src/typecheck.rs
Lines 390 to 398 in a633019
| // `None` if the action entity is not defined in the schema. | |
| // This will only show up if we're typechecking with a | |
| // request environment that was not constructed from the | |
| // schema cross product, which will not happen through our | |
| // public entry points, but it can occur if calling | |
| // `typecheck` directly which happens in our tests. | |
| None => TypecheckAnswer::fail( | |
| ExprBuilder::new().with_same_source_loc(e).var(Var::Action), | |
| ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my case, all of the request environments are from the schema cross product so we should be okay I think.
But either way, I've rewritten the code to do full validation first, then get the type-annotated policies.
2445b74 to
ad8e43b
Compare
khieta
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! I just left some small nit-picky comments
793c7ea to
d2f0caa
Compare
Signed-off-by: oflatt <[email protected]>
Signed-off-by: oflatt <[email protected]>
Signed-off-by: oflatt <[email protected]>
This reverts commit 65c1324. Signed-off-by: oflatt <[email protected]>
Signed-off-by: oflatt <[email protected]>
Signed-off-by: oflatt <[email protected]>
Signed-off-by: oflatt <[email protected]>
Signed-off-by: oflatt <[email protected]>
Signed-off-by: oflatt <[email protected]>
Signed-off-by: oflatt <[email protected]>
Co-authored-by: Kesha Hietala <[email protected]> Signed-off-by: oflatt <[email protected]>
Co-authored-by: Kesha Hietala <[email protected]> Signed-off-by: oflatt <[email protected]>
Co-authored-by: Kesha Hietala <[email protected]> Signed-off-by: oflatt <[email protected]>
Co-authored-by: Kesha Hietala <[email protected]> Signed-off-by: oflatt <[email protected]>
Signed-off-by: oflatt <[email protected]>
Signed-off-by: oflatt <[email protected]>
d9b2950 to
ad96bd3
Compare
This reverts commit 919a916.
This reverts commit 919a916. Signed-off-by: Andrew Wells <[email protected]>
Signed-off-by: Andrew Wells <[email protected]>
This reverts commit 919a916.
Description of changes
This PR implements RFC #74 behind a new feature flag "entity-manifest".
It adds:
compute_entity_manifest(with experimental warning)EntityManifest, RootAccessTrie, AccessTrie, EntitySliceError. (with experimental warning)Note that there's a TODO in the
compute_entity_manifestfunction about returning type errors.Follow up PRs
Entitiesstore from an existingEntitiesstore. This enables strong corpus testing.Checklist for requesting a review
The change in this PR is (choose one, and delete the other options):
cedar-policy(e.g., changes to the signature of an existing API).cedar-policy(e.g., addition of a new API).cedar-policy.cedar-policy-core,cedar-validator, etc.)I confirm that this PR (choose one, and delete the other options):
I confirm that
cedar-spec(choose one, and delete the other options):cedar-spec, and how you have tested that your updates are correct.)cedar-spec. (Post your PR anyways, and we'll discuss in the comments.)